﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DocumentManagement.Models;
using System.ComponentModel;
using System.Windows;
using System.Windows.Data;

namespace DocumentManagement.ViewsModels
{
    public class ReportDocumentINDateViewsModel : ViewsModelBase
    {
        public QSHCEntities1 _entityModels;
        public QSHCEntities1 EntityModels
        {
            get { return _entityModels; }
            set
            {
                if (_entityModels != value)
                {
                    _entityModels = value;
                    OnPropertyChanged("EntityModels");
                }
            }
        }

        public ICollectionView _myReceiveICV;
        public ICollectionView MyReceiveICV
        {
            get { return _myReceiveICV; }
            set
            {
                if (_myReceiveICV != value)
                {
                    _myReceiveICV = value;
                    OnPropertyChanged("MyReceiveICV");
                }
            }
        }

        private int _myText1;
        public int MyText1
        {
            get { return _myText1; }
            set
            {
                if (_myText1 != value)
                {
                    _myText1 = value;
                    OnPropertyChanged("MyText1");
                }
            }
        }
        private int _myText2;
        public int MyText2
        {
            get { return _myText2; }
            set
            {
                if (_myText2 != value)
                {
                    _myText2 = value;
                    OnPropertyChanged("MyText2");
                }
            }
        }
        private int _myText3;
        public int MyText3
        {
            get { return _myText3; }
            set
            {
                if (_myText3 != value)
                {
                    _myText3 = value;
                    OnPropertyChanged("MyText3");
                }
            }
        }
        private DateTime? _myDateDocInFrom;
        public DateTime? MyDateDocInFrom
        {
            get { return _myDateDocInFrom; }
            set
            {
                if (_myDateDocInFrom != value)
                {
                    _myDateDocInFrom = value;
                    OnPropertyChanged("MyDateDocInFrom");
                }
            }
        }
        private DateTime? _myDateDocInTo;
        public DateTime? MyDateDocInTo
        {
            get { return _myDateDocInTo; }
            set
            {
                if (_myDateDocInTo != value)
                {
                    _myDateDocInTo = value;
                    OnPropertyChanged("MyDateDocInTo");
                }
            }
        }
        public ReportDocumentINDateViewsModel()
        {
            if (!DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            {
                EntityModels = new QSHCEntities1();
               

            }

        }
        public void CheckDateReport() //DateTime? MyDateDocInFrom, DateTime? MyDateDocInTo
        {
            //.ToList().Where(p => p.ReceiveDate >= MyDateDocInFrom.Value.Date).ToList().Where(p => p.ReceiveDate <= MyDateDocInTo.Value.Date).ToList()
            //MessageBox.Show(MyDateDocInFrom.Value.Date.ToString());
            MyReceiveICV = CollectionViewSource.GetDefaultView(EntityModels.Receives.Where(p => p.Active == true).ToList()); //.Where(p => p.Active == true)
            MyReceiveICV.Filter += (o) =>
            {
                Receive p = (o as Receive);

                if (p == null)

                    return false;

                if (MyDateDocInFrom.Value.Date != null && MyDateDocInTo.Value.Date != null)
                {
                    if ((p.ReceiveDate.Date >= MyDateDocInFrom.Value.Date) && p.ReceiveDate.Date <= MyDateDocInTo.Value.Date)
                    {
                        return true;
                    }

                    else
                    {
                        return false;
                    }
                  
                }

                return true;

            };
            //ICollectionView aa = CollectionViewSource.GetDefaultView(EntityModels.Receives.Where(p => p.ReceiveDate >= MyDateDocInFrom.Value.Date).Count());
            //MyText1 = aa.Contains(aa).ToString();

            MyText1 = EntityModels.Receives.Where(p => p.Active == true).Where(p => p.ReceiveDate >= MyDateDocInFrom.Value.Date).Count();
            MyText2 = EntityModels.Receives.Count(p => p.Type == 1);
            MyText3 = EntityModels.Receives.Count(p => p.Type == 2);
     
        }
    }
      
}
